import axios from 'axios';
const server = axios.create();

server.defaults.baseURL = import.meta.env.VITE_BASE_URL;

// 携带Cookie
// server.defaults.withCredentials = true;
// server.defaults.headers['X-Requested-With'] = 'XMLHttpRequest';

// 默认Post请求使用 application/json 形式
server.defaults.headers.post['Content-Type'] = 'application/json';
server.defaults.timeout = 60000;

server.interceptors.request.use((config: any) => {
    //token设置
    if (localStorage.getItem('token')) {
        config.headers.Authorization = localStorage.getItem('token');
    }
    return config;
});
server.interceptors.response.use(
    response => {
        return response.data;
    },
    err => {
        return Promise.reject(err);
    }
);
export default server;
